<?php
class Warehourses extends Eloquent {
    protected $table = 'warehouses';

    public static function Select($shop_id)
    {
        try{

            $query_select="SELECT *  FROM warehouses where shop_id = $shop_id ";
            return DB::select(DB::raw($query_select));
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function Insert($name,$address,$comments,$shop_id)
    {
        try{
                $warehouse = new Warehourses();
                $warehouse->name=$name;
                $warehouse->address=$address;
                $warehouse->comments=$comments;
                $warehouse->shop_id=$shop_id;                      
                $warehouse->save();
                $warehouse_id = $warehouse->id;
                return $warehouse_id;   
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function wareIdisExist($id)
    {
        return self::where('id','=',$id)->count()>0;
    }
    public static function getWareId($name)
    {
        try
        {
            $query_shop_id=self::where('name','=',$name)
                                ->select('id')->first();

            //var_dump($query_shop_id); exit;
            if($query_shop_id)
            {
                return $query_shop_id->id;
            }
            return -1;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function Edit($name,$address,$comments,$warehouse_id)
    {
        try{

            $query_edit =" UPDATE warehouses 
                           SET created_at=CURRENT_TIMESTAMP,updated_at=CURRENT_TIMESTAMP,name = '$name',address='$address' ,comments='$comments'
                           WHERE id = $warehouse_id";
            $query= DB::update($query_edit);
            return $query;

        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function deletedata($warehouse_id){
        try{
            $query_delete ="DELETE FROM warehouses WHERE id = $warehouse_id";
            $delete=DB::delete($query_delete);
            return true;
        }
        catch(Exception $e){
            throw $e;
        }
    }


}

?>
